﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Fjaspx.DB;
using Fjaspx.Common;

namespace Fjaspx.UI.Web.Admin.Article
{
    public partial class ArticleManage : System.Web.UI.Page
    {
        public string channelID = "";
        public string classID = "";
        public string channelBar = "";//导航
        public int pageIndexNow = 1;//页码
        public string ShowPageText = "";
        public string action = "";

        protected void Page_Load(object sender, EventArgs e)
        {

            #region 参数获取
            //-控制分页参数--------------------------------
            if (Request.QueryString["page"] != null)
            {
                try
                {
                    this.pageIndexNow = Convert.ToInt32(Request.QueryString["page"]);
                }
                catch { this.pageIndexNow = 1; }
            }
            else
            {
                this.pageIndexNow = 1;
            }
            //控制查询范围为具体的频道及该频道的类别------ 
            if (Request["channelID"] != "")
            {
                this.channelID = Request.QueryString["channelID"];
            }
            if (Request["Class_ID"] != "")
            {
                this.classID = Request.QueryString["Class_ID"];
            }
            if (Request["action"] != "")
            {
                this.action = Request.QueryString["action"];
            }

            #region"删除"
            if (!string.IsNullOrEmpty(Request.QueryString["actionDel"]))
            {
                if (Request.QueryString["actionDel"].ToString().Equals("del"))
                {
                    string id = Request.QueryString["articleId"].ToString();
                    new Fjaspx.Sys.Bll.Fjaspx_Article().Delete(int.Parse(id));
                    Response.Redirect("ArticleManage.aspx");
                }

            }
            #endregion


            //-----------------------------------
            #endregion
            if (!Page.IsPostBack)
            {
                BindDatas();
            }
        }

        public void BindDatas()
        {
            try
            {
                DataSet ds = DbHelperSQL.Query(" select * from Fjaspx_Article order by artdate desc");
                PagedDataSource pds = new PagedDataSource();
                Pager1.UrlFormat = "?i={0}";//分页格式
                int recordcount, ps;
                ps = 15;
                ///获取数据集绑定
                recordcount = ds.Tables[0].Rows.Count;
                pds.DataSource = ds.Tables[0].DefaultView;
                pds.AllowPaging = true;
                pds.CurrentPageIndex = Pager1.PageIndex - 1;
                pds.PageSize = ps;
                Pager1.PageSize = ps;
                Pager1.RecordCount = recordcount;
                this.articles.DataSource = pds;
                this.articles.DataBind();
            }
            catch { }
        }
        #region 数据绑定
        public void InitBindData(string _channelId, string _classId)
        {

        }
        #endregion

        #region 处理文章是否置顶、是否推荐
        public string changeBoolString(bool valParam, string writeStr, string writeStrOther)
        {
            return (valParam) ? writeStr : writeStrOther;
        }
        #endregion

        #region 处理发布者
        public string dealSpaceVal(string str)
        {
            return string.IsNullOrEmpty(str) ? "匿名" : str;
        }
        #endregion

        #region 处理文章状态(审核)
        public string changeIntString(int valParam, string writeStr, string writeStrOther)
        {
            return (valParam == 1) ? writeStr : writeStrOther;
        }
        #endregion

        public string CutString(string str)
        {
            return StringHelper.CutString(str, 40);
        }

        #region 绑定频道与类别
        public string retChannelOrClass(string classId, string channelId, string typeId)
        {
            string retStr = "";
            string hrefRet = "";
            try
            {

            }
            catch { }
            return hrefRet;
        }
        #endregion

        public void delBtn_OnClick(object sender, EventArgs e)
        {
            try
            {
                Response.Redirect(Request.UrlReferrer.ToString());

            }
            catch { }
        }

        public int getIsPower(object obj)
        {
            int reInt = 1;

            return reInt;
        }
    }
}